package de.rs.espresso.algorithms;

import java.util.List;

import de.rs.espresso.covers.DefaultCover;
import de.rs.espresso.interfaces.IAlgorithm;
import de.rs.espresso.interfaces.ICover;
import de.rs.espresso.interfaces.ICube;
import de.rs.espresso.interfaces.IGlobalInformation;
import de.rs.espresso.tools.Statistics;

public class Reduce implements IAlgorithm {
	
	
	private IGlobalInformation info;

	public Reduce(IGlobalInformation info) {
		this.info = info;
	}
	

	@Override
	public ICover compute(ICover onSet, ICover offSet, ICover dcSet) {
		
		long measurementId = Statistics.startMeasurement("REDUCE");
		
		//TODO: better results by sorting after each cube?!
		onSet.sortByCubeWeight();
		
		for (int i = 0; i <onSet.size(); i++) {
			
			ICube cube = onSet.get(i);
			
			ICover q = onSet.clone();
			q.addAll(dcSet);
			q.remove(cube);
			
			ICover cofactor = q.getCofactor(cube);
			
			ICover complement = cofactor.getComplement();
			
			ICube supercube = complement.getSupercube();
			
			ICube intersection = cube.and(supercube);
	
			onSet.set(i, intersection);
			
			
		}
		
		Statistics.stopMeasurement(measurementId);
		
		return onSet;
	}


}
